package org.micode.demo.web.config;

import lombok.extern.slf4j.Slf4j;
import org.micode.demo.biz.service.BizConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

@Slf4j
@Configuration
public class InitConfig implements ApplicationRunner {

    @Autowired
    private BizConfigService bizConfigService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 在应用程序启动完成之后，要执行的东西写在这里
        bizConfigService.loadSysConfig();
        bizConfigService.loadSysDictionary();
    }

    /**
     * 凌晨定时 01:30 重新加载一轮系统配置
     */
    @Scheduled(cron = "0 30 1 * * ?")
    public void reloadSysConfig() {
        bizConfigService.loadSysConfig();
        bizConfigService.loadSysDictionary();
    }

}
